import Vue from 'vue'
import Axios from 'axios'
import API from '../api/api'
// import mock from '../mock/mock'
require('../mock/mock')

const http = Axios.create({
  baseURL: 'http://127.0.0.1/8080',
  timeout: 5000,
  method: 'get',
  headers: {
    'Content-Type': 'application/json; charset=utf-8',
    'Accept': 'application/json'},
  withCredentials: true
})

http.interceptors.request.use(config => {
  //  do something with config
  return config
}, error => {
  // console.log(error)
  return Promise.reject(error)
})

http.interceptors.response.use(res => {
  //  do something with response data
  return res
}, error => {
  // console.log(error)
  return Promise.reject(error)
})

http.get(API.PROD_LIST).then(res => {
  res.headers = 'headers'
  // console.log(res)
})

export default {
  install () {
    Vue.prototype.$http = http
    Vue.http = http
  }
}
